#include "DXUT.h"
#include "DXUTDirect3D9Support.h"

DXUTDirect3D9Support *DXUTDirect3D9Support::GetInstance()
{
	return new DXUTDirect3D9Support();
}

DXUTDirect3D9Support::DXUTDirect3D9Support()
{
}

//--------------------------------------------------------------------------------------
// Rejects any D3D9 devices that aren't acceptable to the app by returning false
//--------------------------------------------------------------------------------------
bool DXUTDirect3D9Support::IsDeviceAcceptable( D3DCAPS9 const *caps, D3DFORMAT adapterFormat, D3DFORMAT backBufferFormat, bool windowed )
{
    // Typically want to skip back buffer formats that don't support alpha blending
    IDirect3D9* pD3D = DXUTGetD3D9Object();
    if( FAILED( pD3D->CheckDeviceFormat( caps->AdapterOrdinal, caps->DeviceType,
                                         adapterFormat, D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING,
                                         D3DRTYPE_TEXTURE, backBufferFormat ) ) )
        return false;

    return true;
}

//--------------------------------------------------------------------------------------
// Create any D3D9 resources that will live through a device reset (D3DPOOL_MANAGED)
// and aren't tied to the back buffer size
//--------------------------------------------------------------------------------------
HRESULT DXUTDirect3D9Support::OnCreateDevice( IDirect3DDevice9 *device, D3DSURFACE_DESC const *backBufferSurfaceDesc )
{
    return S_OK;
}

//--------------------------------------------------------------------------------------
// Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT) 
// or that are tied to the back buffer size 
//--------------------------------------------------------------------------------------
HRESULT DXUTDirect3D9Support::OnResetDevice( IDirect3DDevice9 *device, D3DSURFACE_DESC const *backBufferSurfaceDesc )
{
    return S_OK;
}

//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void DXUTDirect3D9Support::OnFrameRender( IDirect3DDevice9 *device, double time, float elapsedTime )
{
    HRESULT hr;

    // Clear the render target and the zbuffer 
    V( device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) );

    // Render the scene
    if( SUCCEEDED( device->BeginScene() ) )
    {
        V( device->EndScene() );
    }
}

//--------------------------------------------------------------------------------------
// Release D3D9 resources created in the OnD3D9ResetDevice callback 
//--------------------------------------------------------------------------------------
void DXUTDirect3D9Support::OnLostDevice()
{

}

//--------------------------------------------------------------------------------------
// Release D3D9 resources created in the OnD3D9CreateDevice callback 
//--------------------------------------------------------------------------------------
void DXUTDirect3D9Support::OnDestroyDevice()
{

}